    <div class="container">
      <div class="bg-putih">

        <div class="jdl-page">
          Transaksi Penjualan
          <a href="<?php echo site_url('transaksi_penjualan/laporan'); ?>" class="btn btn-warning btn-sm pull-right">
            <span class="fa fa-print"></span>
            Laporan
          </a>
          <div class="clearfix"></div>
        </div>
        
        <?php echo display_flash(); ?>
        
        <div class="row form-horizontal">
          <div class="col-xs-4" style="padding-top: 30px;">
            <div class="form-group">
              <label class="col-xs-5 control-label">Masukkan Item</label>
              <div class="col-xs-7">
                <select id="obat" class="form-control" name="obat">
                  <?php
                    foreach ($obat as $value) {
                     echo "<option value=$value[KdObat]>$value[NmObat]</option>";
                    }
                  ?>
                </select>
              </div>
            </div>
          </div>
          <div class="col-xs-2" style="padding-top: 30px;">
            <div class="form-group">
              <label class="col-xs-4 control-label">Jumlah</label>
              <div class="col-xs-8">
                <input type="text" name="jumlah" id="jumlah" class="form-control input-sm" placeholder="Jumlah" value="1">
              </div>
            </div>
          </div>
          <div class="col-xs-2" style="padding-top: 30px;">
            <div class="form-group">
              <div class="col-xs-12">
                <input type="submit" id="tambah_cart" class="btn btn-primary" value="Beli">
              </div>
            </div>
          </div>
          <div class="col-xs-4">
            <div class="text-right jml-harga">
              <span id="total_transaksi">
                <?php echo formatAngka($this->cart->total()); ?>
              </span>
            </div>
          </div>
        </div>

        <table class="table table-striped table-hover margintop20">
          <thead>
            <tr>
              <th width="3%" style="text-align:center;">No</th>
              <th width="15%">Kode</th>
              <th width="37%">Nama Item</th>
              <th width="10%">Jumlah</th>
              <th width="10%">Harga</th>
              <th width="10%">Total</th>
              <th width="15%"></th>
            </tr>
          </thead>
          <tbody id="transaksi">
            <?php
              $cart = count($this->cart->contents());
              if($cart > 0){
                $no = 1;
                foreach ($this->cart->contents() as $items) {
                  ?>
                    <tr>
                      <td align="center"><?php echo $no++ ?></td>
                      <td><?php echo $items['id']; ?></td>
                      <td><?php echo $items['name']; ?></td>
                      <td><?php echo $items['qty']; ?></td>
                      <td align="right"><?php echo formatAngka($items['price']); ?></td>
                      <td align="right"><?php echo formatAngka($jumlah = $items['qty'] * $items['price']); ?></td>
                      <td>
                        <span class="pull-right">
                          <a href="#" onClick="return deleteCart('<?php echo $items['rowid'] ?>')" class="label label-danger" title="Hapus">Hapus</a>
                        </span>
                      </td>
                    </tr>
                  <?php
                }
              }else{
            ?>
            <tr>
              <td colspan="7" align="center">Tidak ada data</td>
            </tr>
            <?php
              }
            ?>
          </tbody>
        </table>
        <hr />
        <?php echo form_open('transaksi_penjualan/simpan_transaksi', array('role' => 'form', 'id' => 'form'));?>
        <div class="row">
          <div class="col-xs-7 form-horizontal">
            <div class="form-group">
              <label class="col-xs-2 control-label">Keterangan</label>
              <div class="col-xs-10">
                <textarea name="keterangan" class="form-control input-sm" placeholder="Keterangan"></textarea>
              </div>
            </div>
          </div>
          <div class="col-xs-5 form-horizontal">
            <div class="form-group">
              <label class="col-xs-4 control-label">Subtotal</label>
              <div class="col-xs-8">
                <span id="subtotal">
                  <input type="text" style="text-align: right;" id="subtotal" class="form-control input-sm" value="<?php echo formatAngka($this->cart->total()); ?>" disabled>
                </span>
              </div>
            </div>
            <div class="form-group">
              <label class="col-xs-4 control-label">Pembayaran</label>
              <div class="col-xs-8">
                <input type="text" style="text-align: right;" id="bayar" class="form-control input-sm" onkeyup="return kembalian()">
              </div>
            </div>
            <div class="form-group">
              <label class="col-xs-4 control-label">Kembalian</label>
              <div class="col-xs-8">
                <span id="kembalian">
                  <input type="text" style="text-align: right;" class="form-control input-sm" disabled>
                </span>
              </div>
            </div>
          </div>
        </div>
        <input type="submit" class="btn btn-info btn-lg pull-right" value="Simpan">
        <?php echo form_close();?>
        <div class="clearfix"></div>
      </div>
    </div> <!-- /container -->

    <script type="text/javascript">
      $(document).ready(function() {
        $("#obat").select2();
      });
    </script>

    <script>
      $(document).ready(function(){
        $('#tambah_cart').click(function () {
          var KdObat = $('#obat').val();
          var Jumlah = $('#jumlah').val();
          $.ajax({
            url: "<?php echo base_url(); ?>transaksi_penjualan/add_cart",
            type: "POST",
            data: "KdObat=" + KdObat + "&Jumlah=" + Jumlah,
            success: function(data){
              $("#transaksi").html(data);
              $.ajax({
                url: "<?php echo base_url(); ?>transaksi_penjualan/total",
                success: function(data){
                  $("#total_transaksi").html(data);
                }
              });

              $.ajax({
                url: "<?php echo base_url(); ?>transaksi_penjualan/subtotal",
                success: function(data){
                  $("#subtotal").html(data);
                }
              });
            }
          });
        });
      });

      function deleteCart(rowid){
        $.ajax({
          url: "<?php echo base_url(); ?>transaksi_penjualan/delete_cart",
          type: "POST",
          data: "id=" + rowid,
          success: function(data){
            $("#transaksi").html(data);
            $.ajax({
              url: "<?php echo base_url(); ?>transaksi_penjualan/total",
              success: function(data){
                $("#total_transaksi").html(data);
              }
            });

            $.ajax({
              url: "<?php echo base_url(); ?>transaksi_penjualan/total",
              success: function(data){
                $("#subtotal").html(data);
              }
            });
          }
        });
      };

      function kembalian(){
        var bayar = $('#bayar').val();
        $.ajax({
          url: "<?php echo base_url(); ?>transaksi_penjualan/kembalian",
          type: "POST",
          data: "bayar=" + bayar,
          success: function(data){
            $("#kembalian").html(data);
          }
        });
      };
    </script>